let isGameover=false;
let isStart=true;
    export default class BirdCtrl extends Laya.Script {

    constructor() { 
        super(); 
        /** @prop {name:jump, tips:"数字类型示例", type:Number, default:null}*/
        this.jump=null;
        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    } 
    static getGameover(){
        return isGameover;
    }
    onAwake(){
        Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.mouseDown);
        Laya.stage.on("Again",this,this.againGame);
        this.owner.getComponent(Laya.RigidBody).type="static";
        Laya.stage.on("Start",this,function(){
            this.owner.getComponent(Laya.RigidBody).type="dynamic";
            isStart=false;
        })
    }
    againGame(){
        isGameover=false;
        this.owner.pos(561,411);
        this.owner.rotation=0;
        this.owner.autoAnimation="Idle";
        this.owner.getComponent(Laya.RigidBody).linearVelocity={x:0,y:0};
    }
    mouseDown(){
        if(isStart)return;
        if(isGameover)return;
       this.owner.getComponent(Laya.RigidBody).linearVelocity={x:0,y:this.jump};
        this.owner.autoAnimation="Fly";
        Laya.SoundManager.playSound("res/Audio/fly.wav",1);
        this.owner.loop=false;
        }
    onUpdate(){
        if(this.owner.isPlaying==false){
            this.owner.autoAnimation="Idle";
        }
    }
    onTriggerEnter(other){
        if(other.owner.name=="Top")return;
        this.owner.rotation=0;
        this.owner.autoAnimation="Die";
        Laya.SoundManager.playSound("res/Audio/die.wav",1);
        isGameover=true;
        Laya.stage.event("Gameover");
    }

}